﻿#ifndef CLOUDPROTOCOL_H
#define CLOUDPROTOCOL_H

#include <QObject>
#include "Protocol/BaseProtocol.h"
#include "DataType/PortStruct.h"
#include "System/CheckCode.h"

class CloudProtocol : public BaseProtocol
{
    Q_OBJECT
public:
    explicit CloudProtocol(QObject *parent = 0);
    QList<Package> parseData(QByteArray data);
    QByteArray generateData(Package package);

    enum FunctionCode
    {
        Response = 0x01,
        Handshake = 0x02,
        HandshakeSucceed = 0x03,
        Heartbeat = 0x04,
        AppSearch = 0x05,
        AppSearchResponse = 0x06,
        GatewayLogin = 0x08,
        UserLogin = 0x0B,
        StateSync = 0x0F,
        UserLogout = 0x10,
        UserLoginSucceed = 0x11,
        ControlPoint = 0x12,
        DownloadCustomSceneRequest = 0x17,
        DownloadCustomScene = 0x18,
        CustomSceneControl = 0x1A,
        UpdateCustomScene = 0x1B,
        DownloadAutomaticRequest = 0x1E,
        DownloadAutomatic = 0x1F,
        UpdateAutomatic = 0x21,
        UpdatePoint = 0x29,

        SetUPZigbee3=0x40,
        AllowtoJoinZigbee3=0x41,
        ApplytoQuitZigbee3=0x42,
        ZBQuitFeedBack=0x43,
        QueryZigbee3Properties=0x44,
        ZBPropertiesFeedBack=0x45,
        SuccessToJoinZigbee3=0x46,
        SetZigbee3Data=0x49,
        QueryZigbee3Data=0x47,
        PhoneToAllocation=0x4D,
        RS485SetTime=0x4F,

        QueryOtherEquipment=0x50,

        Zigbee3InfraredOPlearn=0x5a,
        Zigbee3InfraredlearnSeccess=0x5b,
        zigbee3InfraredTest=0x5c,
        zigbee3InfraredSave=0x5d,



        DownloadPointListRequest = 0x2A,
        DownloadPointList = 0x2B,
        GatewayLoginSucceed = 0x2C,
        DownloadFileRequest = 0x0C,
        DownloadFile = 0x2E,
        Reboot       = 0x30,
        UpperSearch = 0xA1,
        UpperSearchResponse = 0xA2,
        UpperSetNetParam = 0xA3,
        UpperSetMacParam = 0xA4,
        UpperSetTempNetParam = 0xA9,
        DownloadFileResult = 0x3A,
        GatewayUserStata    =0x3E,
        HeartBest           =0x8A,
        DownloadLogFile     =0x52,
        UpperSetKNXMac = 0xA6,
        UpperSetKNXMacResponse = 0xA7,
    };

    enum ResponseCode
    {
        Succeed = 0,
        CmdBodyError = 4,
        AesLengthError = 36,
        ClientTypeError = 37,
        LoginTimeError = 12,
        AccountNullError = 31,
        PasswordNullError = 32,
        AccountUnboundError = 39,
        PasswordWrongError = 34,
    };

private:

    enum CheckSteps
    {
        CHECK_HEAD,
        CHECK_VERSION,
        CHECK_ID,
        CHECK_FUNCTION,
        CHECK_LENGTH,
        CHECK_BODY,
        CHECK_CHECKCODE,
    };

};

#endif // THIRDPROTOCOL_H
